<template>
    <div class="ph-color-hac" :style="style">
        <div class="ph-color-c"></div>
        <div class="ph-color-ha">
            <ph-slider 
                @change="onHue"
                format="v°"
                :value="hua" 
                :transparent="true" 
                :max="360" 
                class="ph-color-h"/>
            <ph-slider 
                @change="onAlpha"
                :value="alpha*10" 
                :transparent="true" 
                :max="10" 
                class="ph-color-a"/>
        </div>
    </div>
</template>
<script lang="ts">
import { computed, defineComponent } from 'vue'
import { PhSlider } from '../slider'

export default defineComponent({
    components:{PhSlider},
    props:{
        value:{
            type:String,
            default:""
        },
        alpha:{
            type:Number,
            default:1
        },
        hua:{
            type:Number
        }
    },
    setup(props,{emit}){
        const style = computed(()=>{
            return {
                "--ph-color-preview":props.value,
                "--ph-color-nonalpha":props.value.substr(0,7),
            }
        })
        const onHue = (d:number)=>{
            emit("hue",d)
        }
        const onAlpha = (d:number)=>{
            emit("alpha",d/10)
        }
        return {style,onHue,onAlpha}
    }
})
</script>
<style lang="scss">
.ph-color-hac{
    height: 0.7031rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0  0.2460rem;
    --ph-color-preview:transparent;
    --ph-color-nonalpha:transparent;
    .ph-color-ha{
        min-width: 1.9335rem;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        flex: 1;
    }
    .ph-color-c{
        flex:0 0 auto;
        width: 0.4687rem;
        height: 0.4687rem;
        border-radius: 50%;
        border:1px solid var(--ph-bd-light);
        background-color: #fff;
        background-image: url();
        overflow: hidden;
        position: relative;
        margin-right: 0.16406rem;
        &:after{
            content: "";
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top:0;
            background-color: var(--ph-color-preview);
        }
    }
    .ph-color-h,
    .ph-color-a{
        height: var(--ph-fs-small);
    }
    .ph-color-h{
        background-image: linear-gradient(-90deg,red, #F0F, #00F, #0FF, #0F0, #FF0,red);
    }
    .ph-color-a{
        background-image: url();
        &:after{
            content:"";
            position:absolute;
            width:100%;
            left:0;
            top: 0;
            height: 100%;
            background-image: linear-gradient(90deg,transparent,var(--ph-color-nonalpha));
            border-radius: inherit;
        }
    }
}
</style>
